After learning "break" to jump out of the loop, let's learn our "continue" to jump out of the loop.
continue is not as powerful as break to jump out of the loop. continue can only terminate this cycle and enter the next cycle.
The difference between break and continue is like ours It's like playing chess. Some people are not good at chess. When they see that they are about to lose, they turn off the chessboard and stop playing. This is a break. Some people know that if you lose this sentence, the next one will not win. If you admit defeat and try another game, this is continue.
continue control flow chart is as follows:
continue to jump out of the loop instance, The code is as follows
<?php for($i=0;$i<2;$i++) { for($j=1;$j<4;$j++) { if($j==2) { continue 2; //跳出最近的一个for循环的2次循环(j=2和j=3) } echo '$i='.$i.'$j='.$j."<br>"; } } ?>
Code running results:
Detailed example explanation:
First execute the outermost loop of $i=0, and then execute $ j, when executing to $j==2 and encountering continue 2, it will jump out of the last 2 loops of the for loop, so j=2 cannot be printed,
The above is the detailed content of Detailed explanation of 'continue' examples of PHP jumping out of loops. For more information, please follow other related articles on the PHP Chinese website!